package com.ruoyi.project.naming.shenxiao.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.naming.shenxiao.domain.ShengXiao;
import com.ruoyi.project.naming.shenxiao.service.IShengXiaoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 生肖吉凶Controller
 * 
 * @author shixiangwen
 * @date 2022-05-25
 */
@Controller
@RequestMapping("/naming/shenxiao")
public class ShengXiaoController extends BaseController
{
    private String prefix = "naming/shenxiao";

    @Autowired
    private IShengXiaoService shengXiaoService;

    @RequiresPermissions("naming:shenxiao:view")
    @GetMapping()
    public String shenxiao()
    {
        return prefix + "/shenxiao";
    }

    /**
     * 查询生肖吉凶列表
     */
    @RequiresPermissions("naming:shenxiao:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShengXiao shengXiao)
    {
        startPage();
        List<ShengXiao> list = shengXiaoService.selectShengXiaoList(shengXiao);
        return getDataTable(list);
    }

    /**
     * 导出生肖吉凶列表
     */
    @RequiresPermissions("naming:shenxiao:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShengXiao shengXiao)
    {
        List<ShengXiao> list = shengXiaoService.selectShengXiaoList(shengXiao);
        ExcelUtil<ShengXiao> util = new ExcelUtil<ShengXiao>(ShengXiao.class);
        return util.exportExcel(list, "shenxiao");
    }

    /**
     * 新增生肖吉凶
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存生肖吉凶
     */
    @RequiresPermissions("naming:shenxiao:add")
    @Log(title = "生肖吉凶", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShengXiao shengXiao)
    {
        return toAjax(shengXiaoService.insertShengXiao(shengXiao));
    }

    /**
     * 修改生肖吉凶
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ShengXiao shengXiao = shengXiaoService.selectShengXiaoById(id);
        mmap.put("shengXiao", shengXiao);
        return prefix + "/edit";
    }

    /**
     * 修改保存生肖吉凶
     */
    @RequiresPermissions("naming:shenxiao:edit")
    @Log(title = "生肖吉凶", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShengXiao shengXiao)
    {
        return toAjax(shengXiaoService.updateShengXiao(shengXiao));
    }

    /**
     * 删除生肖吉凶
     */
    @RequiresPermissions("naming:shenxiao:remove")
    @Log(title = "生肖吉凶", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shengXiaoService.deleteShengXiaoByIds(ids));
    }
}
